﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Windows.Forms;

namespace e_TicaretAdmin_Application
{
    public partial class FrmUrun : Form
    {
        public FrmUrun()
        {
            InitializeComponent();
        }

        private void btnUrun_Click(object sender, EventArgs e)
        {
            var frm = new YeniUrun();
            frm.ShowDialog();
            Tazele();

        }

        private void FrmUrun_Load(object sender, EventArgs e)
        {
            Tazele();
        }

        private void Tazele(Expression<Func<Product, bool>> expression = null)
        {
            var categoriList = Program.Db.Products.AsQueryable();
            if (expression != null)
                categoriList = categoriList.Where(expression);
            dataGridView1.DataSource =
                categoriList.Select(d => new { ID = d.Id, Başlık = d.Title, Fiyat = d.Price, Marka = d.Model, Açıklama = d.Description }).ToList();
        }

        private void txtUrun_TextChanged(object sender, EventArgs e)
        {
            Tazele(d => d.Title.Contains(txtUrun.Text) || d.Description.Contains(txtUrun.Text) || d.Model.Contains(txtUrun.Text));
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var id = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            var frm = new YeniUrun { Id = id };
            frm.ShowDialog();
            Tazele();
        }
    }
}
